#ifndef frm_control_TButton_H
#define frm_control_TButton_H
                  
#include "frm_control_TPanel.h"
#include "svl_TTimer.h"

namespace frm { namespace control {

///////////////////////////////////////////////////////////////////////////////

struct TButton : public control::TPanel
{
  struct TStyle : public frm::TStyle
  {
    svl_Type(frm::TStyle)
    TPanel::TStyle Normal,Down,Flat,Disable;
	bool EnTimer;
    //
    void SetDefault();
    //
    virtual void SetFromParent(frm::TStyle *Parent);
    virtual svl::TInfoParam AddInfoTo(svl::TInfoParam Info);
  };
  ////////////////////////////////////////////////////////
  struct TEventsList; struct TEvents : public svl::TEvents
  {
    ///////////////////////////////////////////
    struct TParam : public svl::TEvents::TParam
    {
      TButton &Sender;
      //
      TParam(TEventsList &eventsList) : svl::TEvents::TParam(eventsList),Sender(eventsList.Sender) {}
    };
    /////////////////////////////
    struct TClick : public TParam
    {
      TClick(TEventsList &eventsList) : TParam(eventsList) {}
    };
    virtual void TEvents_Click(TClick &Param) { TEvents *P = (TEvents*)Param.GetPrev(); if (P) { P->TEvents_Click(Param);} }
    //
    virtual void TEvents_BeforeChangeDown(TI&I,TButton &Sender,bool OldDown,bool &NewDown) { TEvents *P = (TEvents*)I.GetPrev(); if (P) { P->TEvents_BeforeChangeDown(I,Sender,OldDown,NewDown);} }
    virtual void TEvents_AfterDown       (TI&I,TButton &Sender)                            { TEvents *P = (TEvents*)I.GetPrev(); if (P) { P->TEvents_AfterDown(I,Sender);} }
  };
  ////////////////////////////////////////////
  struct TEventsList : public svl::TEventsList
  {
    TButton &Sender;
    //
    TEventsList(TButton &sender) : Sender(sender),svl::TEventsList(Default()) {}
    //
    void Link  (TEvents &V) { svl::TEventsList::Link  (V);}
    void Unlink(TEvents &V) { svl::TEventsList::Unlink(V);}
    //
    void Click(TEvents::TClick &Param);
    //
    TEvents &Get() { return (TEvents&)svl::TEventsList::GetBot();}
    
  private:
    static TEvents &Default() { static TEvents E; return E;}
  }
  Events;
  //
  TButton(TWindow &Window);
  //
  TButton &SetStyle(TStyle &V);
  //
  void SetEnable(bool V = true) { enable = V;}
  void SetEnTimer(bool V = true) { enTimer = V; }
  bool GetEnable() { return enable;}
  virtual void UpdateEnable(bool V);
  //
  void SetKeepDown(bool V = false) { keepDown = V;}
  bool GetDown() { return down;}
  virtual void UpdateDown(bool V);
  virtual void Click() {};// UpdateDown(true); }

protected:
  virtual void TComponent_Mouse(TMouse Mouse);
  virtual void TComponent_MouseEnter();
  virtual void TComponent_MouseExit ();
  virtual void TComponent_InheritStyleFrom(TTableOfStyles &ParentStyles);

private:
  bool keepDown,down,enable,enTimer,timerActive;
  TStyle *style;
  svl_Except;
  
public:
  
  struct TButtonTimer : public svl::TTimer, frm::TDebug
  {
    TButtonTimer( TButton *button, DWORD _start, DWORD _period );
	//
	void TTimer_Tick();
  
  private:  
	TButton *Button;
	
	svl_Except;
  } *Timer;

};

///////////////////////////////////////////////////////////////////////////////
}}

#endif
